package com.cug.nageoffer.common.controller;

import com.cug.nageoffer.common.service.JobService;
import com.cug.nageoffer.model.entity.Job;
import com.cug.nageoffer.model.vo.JobVo;
import com.cug.nageoffer.model.vo.Result;
import com.cug.nageoffer.model.vo.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "前台岗位相关")
@RestController
@RequestMapping(value = "/api/index/job")
@Slf4j
public class JobController {

    @Autowired
    private JobService jobService;

    @Operation(summary = "根据分类名称查询岗位")
    @GetMapping(value = "/getJobsByCategoryName/{pageNum}/{pageSize}")
    public Result<PageInfo<JobVo>> getJobsByCategoryName(@RequestParam("categoryName") String categoryName
            , @PathVariable Integer pageNum, @PathVariable Integer pageSize){
        log.info("根据分类名称查询岗位，分类名称：{}，第{}页，每页{}条", categoryName, pageNum, pageSize);
        PageInfo<JobVo> pageInfo = jobService.getJobsByCategoryName(categoryName, pageNum, pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "根据公司id查询岗位")
    @GetMapping(value = "/getByEnterpriseId/{id}")
    public Result<List<JobVo>> getByEnterpriseId(@PathVariable Long id){
        List<JobVo> jobs = jobService.getByEnterpriseId(id);
        return Result.build(jobs, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "根据岗位id查询岗位")
    @GetMapping(value = "/getById/{id}")
    public Result<Job> getById(@PathVariable Long id){
        return Result.build(jobService.getById(id),ResultCodeEnum.SUCCESS);
    }

}
